class TimeFormater{
	constructor(timeStamp) {
	    
	}
	
	timeStampToDate(timeStamp,time=false){
		var date = new Date(timeStamp);
		var Y = date.getFullYear() + '-';
		var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
		var D = (date.getDate() < 10 ? '0'+date.getDate() : date.getDate()) + ' ';
		var h = (date.getHours() < 10 ? '0'+date.getHours() : date.getHours()) + ':';
		var m = (date.getMinutes() < 10 ? '0'+date.getMinutes() : date.getMinutes()) + ':';
		var s = (date.getSeconds() < 10 ? '0'+date.getSeconds() : date.getSeconds());

		let strDate = Y+M+D+h+m+s;
		//　console.log(strDate) //2020-05-08 17:44:56　
		return time?strDate:Y+M+D
	}
	timeIntervalToNow(timeStamp){
		var now = Date.now();
		var a = now - timeStamp;
		var m = 60*1000
		var h = m*60
		var d = h*24
		var z = d*7
		var M = d*30
		var y = d*365
		var result = a<=m?'刚刚':a<m*60?parseInt(a/m) + '分钟前':
					 a<h*24?(parseInt(a/h)<1?1:parseInt(a/h))+'小时前':
					 a<d*7?(parseInt(a/d)<1?1:parseInt(a/d))+'天前':
					 a<z*4?(parseInt(a/z)<1?1:parseInt(a/z))+'周前':
					 a<M*12?(parseInt(a/M)<1?1:parseInt(a/M))+'个月前':(parseInt(a/y)<1?1:parseInt(a/y))+'年前'
		return result
	}
	
}

export default new TimeFormater()